package com.zhiwei.configuration;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class WebUtils {
    public static  <T>Page<T>  startPage(){

        //spring中获取request对象
        ServletRequestAttributes requestAttributes=
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request=requestAttributes.getRequest();

        //基于请求对象获取请求中的参数(....)

        String pageCurrentStr=request.getParameter("pageCurrent");
        String pageSizeStr=request.getParameter("pageSize");
        //判断非空。
        if(pageCurrentStr==null||"".equals(pageCurrentStr))
            pageCurrentStr="1";
        if(pageSizeStr==null||"".equals(pageSizeStr))
            pageSizeStr="8";

        Integer pageCurrent=Integer.parseInt(pageCurrentStr);
        Integer pageSize=Integer.parseInt(pageSizeStr);
        return PageHelper.startPage(pageCurrent,pageSize);
    }
}
